//
//  oldFamilyEditHealthViewController.m
//  laonianbangfamily
//
//  Created by 勇拓 李 on 18/3/30.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldFamilyEditHealthViewController.h"
#import "oldMyParentsViewController.h"

@interface oldFamilyEditHealthViewController ()
@property (weak, nonatomic) IBOutlet UITextView *text_view;

@end

@implementation oldFamilyEditHealthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - initView
- (void)initView
{
    
    self.navigationItem.title = @"家属备注";
    
    _text_view.text = _parent.userRelation.desc;
    
    UIButton *rightbutton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 20)];
    
    //[leftbutton setBackgroundColor:[UIColor blackColor]];
    
    [rightbutton setTitle:@"保存" forState:UIControlStateNormal];
    
    [rightbutton addTarget:self action:@selector(rightbtnTapped:) forControlEvents:UIControlEventTouchDown];
    
    UIBarButtonItem *rightitem = [[UIBarButtonItem alloc]initWithCustomView:rightbutton];
    
    self.navigationItem.rightBarButtonItem = rightitem;
}

- (void)rightbtnTapped:(id)sender
{
    NSString *text = _text_view.text;
    
    if (!text) {
        text = @"";
    }
    
    NSCharacterSet  *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    text = [text stringByTrimmingCharactersInSet:set];
    
    [oldHub waiting:@"保存中.."];
    
    WeakSelf
        
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: _parent.userRelation.rid, @"rid", text, @"desc", nil];
    
    [OLDNetWork httpRequestWithPostPut:URL_EditRelation params:params success:^(id data) {
        [oldHub hideHUD];
        UIViewController *vc = weakSelf.navigationController.viewControllers[[weakSelf.navigationController.viewControllers count] - 2];
        
        if ([vc isKindOfClass:[oldMyParentsViewController class]]) {
            oldMyParentsViewController *oldVc = (oldMyParentsViewController *)vc;
            oldVc.parent = [[oldServer alloc] initWithDictionary:data];
        }
        
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } error:^(NSString *error) {
        [oldHub warningUser:error];
    }];
}

@end
